﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Utils.DT;
namespace GastosService.DataLayer
{
    public class PersistenciaConcepto
    {
        public static List<DTConcepto> GetListConceptoDomain()
        {
            DataModelDataContext dtModel = new DataModelDataContext();

            var conceptos = from c in dtModel.Conceptos
                            select new DTConcepto() { IdConcepto = c.IdConcepto, Concepto = c.NombreConcepto,Descripcion=c.Descripcion };
            
            return conceptos.ToList();
        }

        public static void CrearConcepto(DTConcepto concepto)
        {
            try
            {
                Concepto concept = MappingModelObjecstAndDomainObjects.GetConceptoModel(concepto);

                if (concept != null)
                {
                    using (DataModelDataContext dtModel = new DataModelDataContext())
                    {
                        dtModel.Conceptos.InsertOnSubmit(concept);
                        dtModel.SubmitChanges();
                    }
                }
            }
            catch
            {
                throw new Exceptions.ConceptoExecption("Error al intentar crear el Concepto.");
            }

        }

        public static void DeleteConcepto(DTConcepto concepto)
        {
            Concepto conce = MappingModelObjecstAndDomainObjects.GetConceptoModel(concepto);

            if (conce !=null)
            {
                using (DataModelDataContext  dt=new DataModelDataContext())
                {
                    try
                    {
                        dt.Conceptos.DeleteOnSubmit(conce);
                        dt.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        throw new Exceptions.ConceptoExecption("Error al intentar eliminar el concepto", ex);
                    } 
                }
            }
        }
    }
}